package base.file.api;

import java.io.File;

public class FileConstructorSummary {
    public static void main(String[] args) {
        ContructorFile();
        path();

    }

    public static final void ContructorFile() {
        String path = "C:\\Temp\\test\\infinity-wallpaper.jpg";

        // 1. 构建File对象
        File src = new File(path);
        System.out.println(src.length());

        // 2. 构建File对象
        src = new File("C:/Temp/test/infinity-wallpaper.jpg");
        src = new File("C:/Temp/test/","infinity-wallpaper.jpg");
        System.out.println(src.length());

        // 3. 构建File对象
        src = new File(new File("C:/Temp/test"), "infinity-wallpaper.jpg");
        System.out.println(src.length());

    }

    public static final void path() {
        String path = "C:/Temp/test/infinity-wallpaper.jpg";

        // 绝对路径
        File src = new File(path);
        System.out.println(src.getAbsolutePath());

        // 相对路径
        System.out.println(System.getProperty("user.dir"));
        src = new File("infinity-wallpaper.jpg");
        System.out.println(src.getAbsolutePath());

        // 构建一个不存在的文件
        src = new File("aaa/infinity-wallpaper.jpg");

        System.out.println(src.getAbsolutePath());
    }
}
